﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using control.Biz;

namespace control
{
    public partial class frmQLPhieuXuat : Form
    {
        List<BizPhieuXuatHang> phieuxuats = new List<BizPhieuXuatHang>();
        public frmQLPhieuXuat()
        {
            InitializeComponent();
            phieuxuats = BizPhieuXuatHang.GetAll();
            dataGridView1.AutoGenerateColumns = false;
            dataGridView2.AutoGenerateColumns = false;
            bindGridview1();

        }

        private void bindGridview1()
        {
            dataGridView1.DataSource = null;
            dataGridView1.DataSource = phieuxuats;
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Ban co muon xoa khong ?", "Xac Dinh", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                {
                    BizPhieuXuatHang phieuxuat = phieuxuats[row.Index];
                    phieuxuat.Delete();
                }
                phieuxuats = BizPhieuXuatHang.GetAll();
                bindGridview1();
            }
        }

    

        private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count != 0)
            {
                dataGridView2.DataSource = null;
                dataGridView2.DataSource = phieuxuats[dataGridView1.SelectedRows[0].Index].Items;
            }
            else
            {
                dataGridView2.DataSource = null;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            phieuxuats = BizPhieuXuatHang.Find(textBox1.Text, dateTimePicker1.Value, dateTimePicker2.Value);
            bindGridview1();
        }
    }
}
